//
//  ViewController.m
//  29-tableView_Animation
//
//  Created by Snow on 16/8/23.
//  Copyright © 2016年 Snow. All rights reserved.
//

#import "ViewController.h"
#import "MyTableViewCell.h"
#import "SecondViewController.h"
#import "PushTransitionAnimation.h"
#import "PopTransitionAnimation.h"
#define kReuse @"cell"
@interface ViewController ()<UINavigationControllerDelegate, UITableViewDelegate, UITableViewDataSource>
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationController.delegate = self;
    self.view.backgroundColor = [UIColor redColor];
    self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height) style:UITableViewStylePlain];
    [self.view addSubview:self.tableView];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    [self.tableView registerClass:[MyTableViewCell class] forCellReuseIdentifier:kReuse];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 10;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    MyTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:kReuse];

    return cell;
}
- (nullable id <UIViewControllerAnimatedTransitioning>)navigationController:(UINavigationController *)navigationController animationControllerForOperation:(UINavigationControllerOperation)operation fromViewController:(UIViewController *)fromVC toViewController:(UIViewController *)toVC
{
    if (operation == UINavigationControllerOperationPush) {
        PushTransitionAnimation *push = [[PushTransitionAnimation alloc] init];
        return push;
    } else if (operation == UINavigationControllerOperationPop) {
        PopTransitionAnimation *pop = [[PopTransitionAnimation alloc] init];
        return pop;
    }
    return nil;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 200;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    self.index = indexPath;
    MyTableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
    CGRect rect = [cell.contentView convertRect:cell.imageOfCell.frame toView:self.view];
    self.cgrect = rect;
    SecondViewController *second = [[SecondViewController alloc] init];
    second.cgrect = rect;
    [self.navigationController pushViewController:second animated:YES];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}


@end
